package io.renren.modules.customer.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.common.annotation.SysLog;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.customer.entity.MessageRequestEntity;
import io.renren.modules.customer.service.MessageRequestService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author Sean
 * @email seanla@qq.com
 * @date 2020-03-17 19:29:25
 */
@RestController
@RequestMapping("customer/messagerequest")
public class MessageRequestController extends AbstractController {

    private static final Logger LOGGER = LoggerFactory.getLogger(MessageRequestController.class);

    @Autowired
    private MessageRequestService messageRequestService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("customer:messagerequest:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = messageRequestService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("customer:messagerequest:info")
    public R info(@PathVariable("id") Long id){
		MessageRequestEntity messageRequest = messageRequestService.getById(id);

        return R.ok().put("messageRequest", messageRequest);
    }

    /**
     * 保存
     */
    @SysLog("新增短信请求")
    @RequestMapping("/save")
    @RequiresPermissions("customer:messagerequest:save")
    public R save(@RequestBody MessageRequestEntity messageRequest){
        ValidatorUtils.validateEntity(messageRequest);
		messageRequestService.save(messageRequest);
		messageRequest.setCreateUserId(getUserId());
        messageRequest.setCreateTime(new Date());
        return R.ok();
    }

    /**
     * 修改
     */
    @SysLog("修改短信请求")
    @RequestMapping("/update")
    @RequiresPermissions("customer:messagerequest:update")
    public R update(@RequestBody MessageRequestEntity messageRequest){
        ValidatorUtils.validateEntity(messageRequest);
		messageRequestService.updateById(messageRequest);
        return R.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除短信请求")
    @RequestMapping("/delete")
    @RequiresPermissions("customer:messagerequest:delete")
    public R delete(@RequestBody Long[] ids){
		messageRequestService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
